# -*- coding: UTF-8 -*-
# Author:     yucheng
# CreateTime: 2018/7/2 17:27


"""
使用Flask-Mail和qq邮箱SMTP服务发送邮件
https://blog.csdn.net/wbin233/article/details/73222027
https://www.cnblogs.com/wholeworld/p/6771398.html
"""


from flask_mail import Mail,Message
from flask import Flask
import os

app=Flask(__name__)
app.config.update(
    DEBUG = True,
    MAIL_SERVER='smtp.qq.com',
    MAIL_PROT=25,
    MAIL_USE_TLS = True,
    MAIL_USE_SSL = False,
    MAIL_USERNAME = '908228127@qq.com',
    MAIL_PASSWORD = 'gmvntmmcrolfbfgf',
    # MAIL_PASSWORD = 'gmvntmmcrolfbfgf',
    #MAIL_PASSWORD = 'xxxxxxxx',
    MAIL_DEBUG = True
)
mail=Mail(app)


@app.route('/')
def index():
# sender 发送方哈，recipients 邮件接收方列表
    msg = Message("Hi!This is a test ",sender='908228127@qq.com', recipients=['yovld@126.com'])
# msg.body 邮件正文
    msg.body = "This is a first email"
# msg.attach 邮件附件添加
# msg.attach("文件名", "类型", 读取文件）
#     with app.open_resource("F:\2281393651481.jpg") as fp:
#         msg.attach("image.jpg", "image/jpg", fp.read())

    mail.send(msg)
    print ("OK")
    return "Sent"




if __name__=='__main__':
    app.run(debug=True)